import axios from 'axios'
import { HmMessage } from '@/components/message/message'
/*
1:vue-cli环境变量：根目录  .env.development   VUE_APP_命名=值     process.env.VUE_APP_命名
2:vite环境变量：   根目录  .env.development   VITE_命名=值        import.meta.env.VITE_URL
*/
const _axios = axios.create({
  baseURL: import.meta.env.VITE_URL as string
})
_axios.interceptors.request.use(
  config => {
    return config
  },
  error => {
    return Promise.reject(error)
  }
)
_axios.interceptors.response.use(
  res => {
    return res
  },
  error => {
    if (error.response && error.response.data) {
      HmMessage.error?.(error.response.data.message as string)
    }

    return Promise.reject(error)
  }
)
export default _axios
